home *** CD-ROM | disk | FTP | other *** search
/ Windows Expert / Windows Expert.iso / others / ole_101.zip / PATRON.ZIP / INSDROP.C < prev    next >
C/C++ Source or Header  |  1992-04-13  |  4KB  |  155 lines

  1. /*
  2.  * INSDROP.C
  3.  *
  4.  * Object creation functions for Insert Object and FCreateFromDropFiles.
  5.  *
  6.  * FCreateFromDropFiles creates embedded Packager objects from files
  7.  * dropped from File Manager.
  8.  *
  9.  * Copyright(c) Microsoft Corp. 1992 All Rights Reserved
  10.  */
  11.  
  12. #include <windows.h>
  13. #include <ole.h>
  14. #include <shellapi.h>
  15. #include "oclient.h"
  16. #include "blackbox.h"
  17. #include "patron.h"
  18.  
  19.  
  20. /*
  21.  * FEditInsertObject
  22.  *
  23.  * Purpose:
  24.  *  Invokes the Insert Object dialog handler that shows the dialog
  25.  *  and creates an object if the user selects a valid class name.
  26.  *  We need to create an object name before calling the dialog, and
  27.  *  on return we create a BlackBox window for that object.
  28.  *
  29.  * Parameters:
  30.  *  hWnd            HWND to use as the parent of the dialog.
  31.  *  hInst           HANDLE to the application instance.
  32.  *  pDoc            LPDOCUMENT that contains OLE information.
  33.  *
  34.  * Return Value:
  35.  *  BOOL            TRUE if an object was created, FALSE otherwise.
  36.  */
  37.  
  38. BOOL FAR PASCAL FEditInsertObject(HWND hWnd, HANDLE hInst, LPDOCUMENT pDoc)
  39.     {
  40.     LPOBJECT        pObj;
  41.     FILEOBJECT      fo;
  42.     HWND            hWndT;
  43.  
  44.     if (NULL==pDoc || NULL==hInst)
  45.         return FALSE;
  46.  
  47.     FileObjectDefaults(&fo);
  48.  
  49.     pObj=PObjectInsertDialog(hWnd, hInst, pDoc, fo.szName);
  50.  
  51.     if (NULL==pObj)
  52.         return FALSE;
  53.  
  54.     hWndT=HBlackBoxCreate(hWnd, &fo, TRUE, pObj);
  55.  
  56.     if (NULL==hWndT)
  57.         return FALSE;
  58.  
  59.     return TRUE;
  60.     }
  61.  
  62.  
  63.  
  64.  
  65.  
  66.  
  67. /*
  68.  * FCreateFromDropFiles
  69.  *
  70.  * Purpose:
  71.  *  Creates embedded OLE Packager objects from dropped files in
  72.  *  response to a WM_DROPFILES message.
  73.  *
  74.  * Parameters:
  75.  *  hWnd            HWND on which the files were dropped.
  76.  *  hDrop           HANDLE identifying the dropped files.
  77.  *  pDoc            LPDOCUMENT owner of all OLE objects in this application.
  78.  *
  79.  * Return Value:
  80.  *  BOOL            TRUE if objects were ALL created successfully, FALSE
  81.  *                  otherwise.  Returning FALSE does not mean that some
  82.  *                  objects were not created.
  83.  *
  84.  */
  85.  
  86. BOOL FAR PASCAL FCreateFromDropFiles(HWND hWnd, HANDLE hDrop, LPDOCUMENT pDoc)
  87.     {
  88.     LPOBJECT        pObj;
  89.     FILEOBJECT      fo;
  90.     HWND            hWndT;
  91.     char            szPath[CCHPATHMAX];
  92.     WORD            cFiles;
  93.     WORD            i;
  94.     BOOL            fRet=TRUE;
  95.     BOOL            fTemp;
  96.     OLESTATUS       os;
  97.  
  98.     //Get the number of files dropped.
  99.     cFiles=DragQueryFile(hDrop, (WORD)-1, szPath, CCHPATHMAX);
  100.  
  101.     //For each file, create an object window and call OleCreateFromFile.
  102.  
  103.     for (i=0; i< cFiles; i++)
  104.         {
  105.         //Get the filename for the object.
  106.         DragQueryFile(hDrop, i, szPath, CCHPATHMAX);
  107.  
  108.         //Get the next ID to use for a window.
  109.         FileObjectDefaults(&fo);
  110.         pObj=PObjectAllocate(&fTemp, pDoc);
  111.  
  112.         if (!fTemp)
  113.             {
  114.             PObjectFree(pDoc, pObj);
  115.             fRet=FALSE;
  116.             continue;
  117.             }
  118.  
  119.         /*
  120.          * Create a Packager object from a file, using "Package" as
  121.          * the class and the filename given from DragQueryFile.
  122.          */
  123.         os=OleCreateFromFile(PSZOLE(IDS_STDFILEEDITING), (LPOLECLIENT)pObj,
  124.                              PSZOLE(IDS_PACKAGE), szPath, pDoc->lh, fo.szName,
  125.                              &pObj->pObj, olerender_draw, 0);
  126.  
  127.         if (OLE_OK!=OsError(os, pDoc, pObj, TRUE))
  128.             {
  129.             PObjectFree(pDoc, pObj);
  130.             fRet=FALSE;
  131.             continue;
  132.             }
  133.  
  134.         /*
  135.          * If we really wanted to be picky, we could call DragQueryPoint to
  136.          * determine where the object was dropped, but it's of little
  137.          * consequence in this application, so we'll simply use default
  138.          * placement.
  139.          */
  140.  
  141.         /*
  142.          * Creating a window make the file dirty, so we don't have to.
  143.          * This also allocates an OBJECT and initializes everything it
  144.          * cares to know about.
  145.          */
  146.         hWndT=HBlackBoxCreate(hWnd, &fo, TRUE, pObj);
  147.  
  148.         if (NULL==hWndT)
  149.             fRet=FALSE;
  150.         }
  151.  
  152.     DragFinish(hDrop);
  153.     return fRet;
  154.     }
  155.